import { roleTypeMap, appCategoriesMap } from './maps'
import userInfo from './userInfo'

// 创建一个 Symbol 作为私有属性
const _applicationConfig = Symbol('applicationConfig')

// 工作台配置对象
class Workbench {
    constructor() {
        // 初始化私有属性
        this[_applicationConfig] = [
            {
                categoryName: '基础应用',
                categoryCode: appCategoriesMap.BASIC_APPLICATION,
                apps: [
                    {
                        code: 'business-management',
                        name: '管理企业',
                        icon: '/static/images/work_glqy.png',
                        page: 'pages/businessManagement/businessManagement',
                        role: [roleTypeMap.ORDINARY_USER, roleTypeMap.LEADER],
                        type: 'entrance',
                        permission: true
                    },
                    {
                        code: 'shop-rules',
                        name: '店铺设置',
                        icon: '/static/images/work_dpsz.png',
                        page: 'pages/shops/shopRules',
                        role: [roleTypeMap.ORDINARY_USER, roleTypeMap.LEADER],
                        type: 'entrance',
                        permission: true
                    },
                    {
                        code: 'tutorial',
                        name: '新手教程',
                        icon: '/static/images/work_xsjc.png',
                        role: [roleTypeMap.ORDINARY_USER, roleTypeMap.LEADER, roleTypeMap.SHOPKEEPER, roleTypeMap.STAFF, roleTypeMap.FINANCES],
                        type: 'plate',
                        permission: false
                    },
                    {
                        code: 'cooperation',
                        name: '我要合作',
                        icon: '/static/images/work_wyhz.png',
                        role: [roleTypeMap.ORDINARY_USER, roleTypeMap.LEADER, roleTypeMap.SHOPKEEPER, roleTypeMap.STAFF, roleTypeMap.FINANCES],
                        type: 'plate',
                        permission: true
                    }
                ]
            },
            {
                categoryName: '功能管理',
                categoryCode: appCategoriesMap.FEATURE_MANAGEMENT,
                apps: [
                    {
                        code: 'product-settings',
                        name: '商品设置',
                        icon: '/static/images/work_spsz.png',
                        page: 'pages/shops/productSettings',
                        role: [roleTypeMap.ORDINARY_USER, roleTypeMap.LEADER],
                        permission: true
                    },
                    {
                        code: 'user-management',
                        name: '用户管理',
                        icon: '/static/images/work_yhgl.png',
                        page: 'pages/userManagement/userManagement',
                        role: [roleTypeMap.ORDINARY_USER, roleTypeMap.LEADER],
                        permission: true
                    },
                    {
                        code: 'group-management',
                        name: '团体管理',
                        icon: '/static/images/work_ttgl.png',
                        page: 'pages/groupManagement/groupManagement',
                        role: [roleTypeMap.ORDINARY_USER, roleTypeMap.LEADER],
                        permission: true
                    },
                    {
                        code: 'debt-management',
                        name: '白条管理',
                        icon: '/static/images/work_btgl.png',
                        page: 'pages/debtManagement/debtManagement',
                        role: [roleTypeMap.ORDINARY_USER, roleTypeMap.LEADER],
                        permission: true
                    },
                    {
                        code: 'prize',
                        name: '奖金池',
                        icon: '/static/images/work_jjc.png',
                        page: 'pages/prize/index',
                        role: [roleTypeMap.ORDINARY_USER, roleTypeMap.LEADER],
                        permission: true
                    },
                    {
                        code: 'data-center',
                        name: '数据中心',
                        icon: '/static/images/work_sjzx.png',
                        page: 'pages/dataCenter/index',
                        role: [roleTypeMap.ORDINARY_USER, roleTypeMap.LEADER],
                        permission: true
                    },
                    {
                        code: 'smart-cabinet-management',
                        name: '智能柜管理',
                        icon: '/static/images/work_znggl.png',
                        page: 'pages/smartCabinetManagement/shopManagement',
                        role: [roleTypeMap.ORDINARY_USER, roleTypeMap.LEADER],
                        permission: true
                    },
                    {
                        code: 'withdrawal',
                        name: '提现审核',
                        icon: '/static/images/work_txsh.png',
                        page: 'pages/work/withdrawalApprovalMain',
                        role: [roleTypeMap.ORDINARY_USER, roleTypeMap.LEADER],
                        permission: true
                    },
                    {
                        code: 'agreement',
                        name: '协议',
                        icon: '/static/images/work_xy.png',
                        page: '',
                        role: [roleTypeMap.ORDINARY_USER, roleTypeMap.LEADER],
                        permission: true
                    },
                    {
                        code: 'distribute-management',
                        name: '分销管理',
                        icon: '/static/images/work_fxgl.png',
                        page: 'pages/distributionManagement/distributionManagement',
                        role: [roleTypeMap.ORDINARY_USER, roleTypeMap.LEADER],
                        permission: true
                    },
                    {
                        code: 'recharge-management',
                        name: '充值管理',
                        icon: '/static/images/work_czgl.png',
                        page: 'pages/rechargeManagement/rechargeManagement',
                        role: [roleTypeMap.ORDINARY_USER, roleTypeMap.LEADER],
                        permission: true
                    },
                    {
                        code: 'income',
                        name: '收入统计',
                        icon: '/static/images/work_srtj.png',
                        page: 'pages/statistic/statistic',
                        role: [roleTypeMap.ORDINARY_USER, roleTypeMap.LEADER],
                        permission: true
                    }
                ]
            },
            {
                categoryName: '订单管理',
                categoryCode: appCategoriesMap.ORDER_MANAGEMENT,
                apps: [
                    {
                        code: 'order',
                        name: '订单',
                        icon: '/static/images/work_dd.png',
                        page: 'pages/order/order',
                        role: [roleTypeMap.ORDINARY_USER, roleTypeMap.LEADER],
                        permission: true
                    },
                    {
                        code: 'pickup-order',
                        name: '收衣订单',
                        icon: '/static/images/work_sydd.png',
                        page: 'pages/receiveClothesOrder/receiveClothesOrder',
                        role: [roleTypeMap.ORDINARY_USER, roleTypeMap.LEADER],
                        permission: true
                    },
                    {
                        code: 'order-review',
                        name: '订单复核',
                        icon: '/static/images/work_ddfh.png',
                        page: 'pages/orderReview/orderReview',
                        role: [roleTypeMap.ORDINARY_USER, roleTypeMap.LEADER],
                        permission: true
                    },
                    {
                        code: 'wash-order',
                        name: '洗涤订单',
                        icon: '/static/images/work_xddd.png',
                        page: 'pages/washOrders/washOrders',
                        role: [roleTypeMap.ORDINARY_USER, roleTypeMap.LEADER],
                        permission: true
                    },
                    {
                        code: 'factory-pickup-order',
                        name: '工厂提单',
                        icon: '/static/images/work_gctd.png',
                        page: 'pages/factoryPickupOrder/factoryPickupOrder',
                        role: [roleTypeMap.ORDINARY_USER, roleTypeMap.LEADER],
                        permission: true
                    },
                    {
                        code: 'delivery-order',
                        name: '派送订单',
                        icon: '/static/images/work_psdd.png',
                        page: 'pages/deliveryOrder/deliveryOrder',
                        role: [roleTypeMap.ORDINARY_USER, roleTypeMap.LEADER],
                        permission: true
                    },
                    {
                        code: 'exception-order',
                        name: '异常订单',
                        icon: '/static/images/work_ycdd.png',
                        page: 'pages/exceptionOrders/exceptionOrders',
                        role: [roleTypeMap.ORDINARY_USER, roleTypeMap.LEADER],
                        permission: true
                    },
                    {
                        code: 'after-sale-order',
                        name: '售后订单',
                        icon: '/static/images/work_shdd.png',
                        page: 'pages/afterSaleOrder/afterSaleOrder',
                        role: [roleTypeMap.ORDINARY_USER, roleTypeMap.LEADER],
                        permission: true
                    },
                    {
                        code: 'back-wash-order',
                        name: '返洗订单',
                        icon: '/static/images/work_fxdd.png',
                        page: 'pages/backWashOrder/backWashOrder',
                        role: [roleTypeMap.ORDINARY_USER, roleTypeMap.LEADER],
                        permission: true
                    },
                    {
                        code: 'hanging-clothes',
                        name: '挂衣',
                        icon: '/static/images/work_gy.png',
                        page: 'pages/hangingClothesOrder/hangingClothesOrder',
                        role: [roleTypeMap.ORDINARY_USER, roleTypeMap.LEADER],
                        permission: true
                    }
                ]
            }
        ]
    }

    get applicationConfig() {
        return this[_applicationConfig]
    }

    // 基础应用
    get basicApps() {
        return (this.applicationConfig.find(({ categoryCode }) => categoryCode === appCategoriesMap.BASIC_APPLICATION)?.apps || []).filter(({ role }) => role.includes(+userInfo.infomation.storeTypeRole))
    }

    // 基础应用入口app
    get basicEntranceApps() {
        return this.basicApps.filter(({ type }) => type === 'entrance')
    }

    // 基础应用板块
    get basicModuleApps() {
        return this.basicApps.filter(({ type }) => type === 'plate')
    }

    // 功能管理
    get featureManageApps() {
        return (this.applicationConfig.find(({ categoryCode }) => categoryCode === appCategoriesMap.FEATURE_MANAGEMENT)?.apps || []).filter(({ role }) => role.includes(+userInfo.infomation.storeTypeRole))
    }

    // 订单管理
    get orderManagementApps() {
        return (this.applicationConfig.find(({ categoryCode }) => categoryCode === appCategoriesMap.ORDER_MANAGEMENT)?.apps || []).filter(({ role }) => role.includes(+userInfo.infomation.storeTypeRole))
    }
}

export default new Workbench()